package terminal.utility;

import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DataManager extends Thread {

    private ArrayList<Field> fieldList;

    public DataManager(ArrayList<Field> fieldList) {
        this.fieldList = fieldList;
    }

    public void run() {
        while (true) {
            try {
                Date d = new Date();
                for (Field f : fieldList) {
                    if (f.getTime().equals("now")) {
                        f.update();
                    } else if (f.getTime().equals(d.toString())) {
                        f.update();
                        f.setNewTime();
                    }
                }
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }
}
